<template>
  <div class="main_box">
    <el-row>
      <el-col :span="12">
        <Crumbs></Crumbs>
      </el-col>
      <el-col :span="12">
        <div class="opration_wrap">
          <el-button type="primary" icon="fa fa-mail-forward" @click="returnList">返回</el-button>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <div class="search_wrap">
        <el-form :inline="true" :model="searchForm" ref="searchForm">
          <el-form-item prop="contact">
            <el-input v-model="searchForm.contact" :clearable="true" placeholder="通讯姓名"></el-input>
          </el-form-item>
          <el-form-item prop="tel">
            <el-input v-model="searchForm.tel" :clearable="true" placeholder="通讯号码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="onSearch">查询</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-row>
    <el-row ref="tableRow">
      <el-table :data="tableList" :fit="true">
        <el-table-column type="index" label="序号" width="50"></el-table-column>
        <el-table-column label="客户姓名" align="center">
          <template>
            <span>{{ this.$route.query.name }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="contact" label="通讯姓名" align="center"></el-table-column>
        <el-table-column prop="tel" label="通讯号码" align="center"></el-table-column>
      </el-table>
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.currentPage"
        :page-sizes="[5, 10, 20, 30]"
        :page-size="page.pageSize"
        layout="total, sizes, jumper, next, pager, prev"
        :total="page.pageTotal"
      ></el-pagination>
    </el-row>
  </div>
</template>
<script>
import Crumbs from '@/components/Crumbs';
import * as message from '@/constants/message';
import { FORMAT_DATE_YYYY_MM_DD } from '@/constants/constants';

export default {
  data() {
    return {
      searchForm: {
        contact: '',
        tel: '',
      },
      page: {
        pageNo: 1,
        pageSize: 20,
        pageTotal: 0,
        currentPage: 1,
      },
      tableList: [],

    };
  },
  components: {
    Crumbs,
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.listTable();
      this.getTableHeight();
    },

    listTable() {
      let data = {
        pageNo: this.page.pageNo,
        pageSize: this.page.pageSize,
        customerId: this.$route.query.id,
        contact: this.searchForm.contact,
        tel: this.searchForm.tel,
      };
      this.fetchData(data);
    },
    handleSizeChange(size) {
      this.page.pageSize = size;
      this.listTable();
    },
    handleCurrentChange(val) {
      this.page.pageNo = val;
      this.listTable();
    },
    onSearch() {
      this.page.pageNo = 1;
      this.listTable();
    },
    resetForm() {
      this.$refs.searchForm.resetFields();
      this.onSearch();
    },
    fetchData(data) {
      this.$emit('show-loading', true);
      this.$Get(this.$Config.api.customerTel, data)
        .then((res) => {
          this.tableList = res.data.list;
          this.page.pageTotal = res.data.total;
          this.page.currentPage = res.data.pageNum;
          this.$emit('show-loading', false);
        })
        .catch((error) => {
          console.error(error);
          this.$emit('show-loading', false);
        });
    },
    returnList() {
      this.$router.push({ name: '客户列表' });
    },
  },
};
</script>
<style lang="scss" src="@/assets/css/views/content.scss" scope></style>
